<?php

namespace Common\Model;
use Think\Model\RelationModel;
class OrgnizeruserclassModel extends RelationModel {
    protected $_link = array(
        'Users'=>array(
            'mapping_type' => self::BELONGS_TO,
            'class_name'    =>'Users',
            'foreign_key' => 'uid'
             ),
         );


    /**
     * 通过oid和json格式信息获得用户列表，searchJsonpara是all的时候取得全部
     * @param $oid
     * @param $searchJsonpara
     * @return array
     */

    public function getUserList($oid, $searchJsonpara)
    {
        $user_class = $this;
        $arr = [];
        if($searchJsonpara == 'all'){
            $data = $user_class->relation(true)->where([ 'oid' => $oid])->select();
            $i = 0;
            foreach($data as $d){
                $arr[$i] = $d['Users'];
                unset($arr[$i]['password']);

                $arr[$i]['class'] = convertClassJson($d['class']);
                $i++;

            }

        }
        else{
            $data = $user_class->relation(true)->where(['class' => $searchJsonpara, 'oid' => $oid])->select();
            $class = convertClassJson($searchJsonpara);

            $i = 0;
            foreach($data as $d){
                $arr[$i] = $d['Users'];
                unset($arr[$i]['password']);
                $arr[$i]['class'] = $class;
                $i++;
            }
        }

        return $arr;

    }

}